<?php 
    require_once("include/game_core.php");    
    require_once(USER_CONTROLLER_FILE);
    if ( ! UserController::isLoggedIn()) {
        header( 'Location: access_denied.php' ) ;
    }

    require_once (GAME_TABLE_FILE);
    require_once(VIEW_BASE_FILE);    
    $view = new view_base();
    $view->ShowHeader();
    $view->ShowMenu("profile");
    $view->ShowConatinerHead();
    
    $wins =  GameTable::getUserLastWinsAndOpponentData();
    $losses =  GameTable::getUserLastLoosesAndOpponentData();
    
?>
<div id="content">
    <table width="100%">
        <tr>
            <td><h2>My Profile</h2></td><td width="65"><img src="images/profile.png"></td>
        </tr>
    </table>
    <h3>How was I ?</h3>
    <br/>
    <table width="100%">
        <tr>
            <td>
                Last games you won <br/>
                <table>
                    <tr>
                        <?php
                            echo '<table width="100%" border ="1">';
                            //echo '<caption>Game_ID Player_1 Player_2 StartTime LastTime Moves</caption>';
                            echo '<tr><th>Duration</th><th>DMG done by you</th><th>Date</th><th>Nick</th><th></th><tr>';
                            if($wins != null) {
                                while($row = $wins->fetch_assoc()) {
                                    echo '<tr><td>' . $row['duration'] . '</td>
                                        <td>' . $row['dmg'] . '</td>
                                        <td>' . $row['date'] . '</td>
                                        <td>' . $row['nick'] . '</td>'
                                        ?><td><img src="images/avatars/<?php echo $row['avatar'];  ?>.png" height="20" width="20"></td><?php
                                }
                            }
                            echo '</table>';
                        ?>
                    </tr>
                </table>
            </td>
            <td>
                
            </td>
        </tr>
    </table>
    <br/>
    <table width="100%">
        <tr>
            <td>
                Last games you lost <br/>
                <table>
                    <tr>
                        <?php
                            echo '<table width="100%" border ="1">';
                            //echo '<caption>Game_ID Player_1 Player_2 StartTime LastTime Moves</caption>';
                            echo '<tr><th>Duration</th><th>DMG done to you</th><th>Date</th><th>Nick</th><th></th><tr>';
                            if($losses != null) {
                                while($row = $losses->fetch_assoc()) {
                                    echo '<tr><td>' . $row['duration'] . '</td>
                                        <td>' . $row['dmg'] . '</td>
                                        <td>' . $row['date'] . '</td>
                                        <td>' . $row['nick'] . '</td>'
                                        ?><td><img src="images/avatars/<?php echo $row['avatar'];  ?>.png" height="20" width="20"></td><?php	
                                }
                            }
                            echo '</table>';
                        ?>
                    </tr>
                </table>
            </td>
            <td>
                
            </td>
        </tr>
    </table>
</div>
<?php include (VIEW_SIDE_FILE); ?>
<?php   $view->ShowFooter();      ?>